#include <vector>
#include <GL/glut.h>
#include "VL/VLfd.h"

#ifndef PARTICLES_H
#define PARTICLES_H

using namespace std;

class Particle
{
public:
	Particle();
	Particle(Vec3d pos, Vec3d vel, float ms);
	void clearForces();

	Vec3d x;
	Vec3d v;
	Vec3d n;
	Vec3d f;
	float m;
	float t;
};

class ParticleSystem
{
public:
	ParticleSystem(unsigned num);
	void computeAccelerations(Vecd Y, Vecd *out);
	void initFireworks(Vec3d gen, float tt);
	void initChain(Vec3d gen);
	void initCloth(int w, int h, bool hanged);
	void initFountain(Vec3d gen, float tt);
	void getState();
	void setState();
	void eulerStep(float dt);
	void rkStep(float dt);
	void draw(bool wireframe);
	void computeCollition(Vec3d c, float r);
	void computeCollition(Vec3d p, Vec3d n);
	void loadTexture(char *filename);
	unsigned S(unsigned r, unsigned c){ return r*pnum/(int)sqrt(pnum)+c; }
	vector<Particle> particles;
	Vec3d generator;
	int pnum;
	int psType;
	GLuint texture[1];
	bool isHanged;
	Vecd X;
	Vecd f;
	int w, h;
	float r;
	float t;
	float ks;
	float vd;
	float pLife;
};

#endif
